/* ******************************************************************
 * This file is part of the escal project and distributed under the
 * terms of the GNU General Public License Version 3
 * Copyright (C) 2008 Epocher (xijiaosdq@gmail.com)
 * See COPYING file for licensing information.
 *******************************************************************/

#ifndef CONFIG_WIDGET_H
#define CONFIG_WIDGET_H
#include "escal.h"
#include "escal_settings.h"
#include "ui_bool_config_widget.h"
#include "ui_list_config_widget.h"
#include "ui_string_config_widget.h"
#include "ui_integer_config_widget.h"
#include <QWidget>
#include <QRadioButton>

class QWidget;
class QStringListModel;
class BaseConfigWidget;

class BaseConfigWindow:public QWidget{
public:
	BaseConfigWindow(QWidget *parent=0);
	virtual ~BaseConfigWindow() {};
	virtual void apply();
	virtual bool isModified();
	virtual void reset();
	virtual void setDefaults();
	virtual void show();
protected:
	QList<BaseConfigWidget *> widgetList;
};
class BoolConfigWidget;
class BaseConfigWidget:public QWidget{
public:
	BaseConfigWidget(const QString &key, const QString &title,
		QWidget *parent=0, BoolConfigWidget *depend=0);
	virtual ~BaseConfigWidget() {};
	virtual bool isModified()=0;
	virtual void reset()=0;
	virtual void setDefault()=0;
	virtual void apply()=0;
	virtual void setKey(const QString &key);
	virtual void setTitle(const QString &title);
protected:
	QString key;
};

class BoolConfigWidget:public BaseConfigWidget,public Ui::BoolConfigWidget{
	Q_OBJECT
public:
	BoolConfigWidget(const QString &key, const QString &title,
			QWidget *parent=0, BoolConfigWidget *depend=0);
	virtual void setTitle(const QString &title);
	bool isModified();
	void reset();
	void setDefault();
	void apply();
	void addDepend(QWidget *widget);
	void removeDepend(QWidget *widget);
private slots:
	void buttonToggled(bool checked);
private:
	QList<QWidget*> dependedWidgets;
};

class IntegerConfigWidget:public BaseConfigWidget,
	public Ui::IntegerConfigWidget
{
public:
	IntegerConfigWidget(const QString &key, const QString &title, 
			int range_min=0, int range_max=100, 
			QString unit=QString(),	QWidget *parent=0,
			BoolConfigWidget *depend=0);
	void setTitle(const QString &text);
	void setUnit(QString unit);
	void setRange(int min, int max);
	bool isModified();
	void reset();
	void setDefault();
	void apply();
};

class ListConfigWidget:public BaseConfigWidget,public Ui::ListConfigWidget{
	Q_OBJECT
public:
	ListConfigWidget(const QString &key, const QString &title, 
			QWidget *parent=0, BoolConfigWidget *depend=0);
	void setTitle(const QString &text);
	bool isModified();
	void reset();
	void setDefault();
	void apply();
protected slots:
	void newItem();
	void editItem();
	void removeItem();
private:
	QStringListModel *listModel;
};

class StringConfigWidget:public BaseConfigWidget,public Ui::StringConfigWidget{
	Q_OBJECT
public:
	StringConfigWidget(const QString &key, const QString &title, 
			QWidget *parent=0, BoolConfigWidget *depend=0);
	void setTitle(const QString &text);
	bool isModified();
	void reset();
	void setDefault();
	void apply();
};


#endif /* CONFIG_WIDGET_H */
